package com.vrv.common.chart.builder;

import java.util.ArrayList;
import java.util.List;

import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;

import com.vrv.common.chart.AbstractAChartEngine;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

public class LineChartBuilder extends AbstractAChartEngine {

    public String getName() {
        return null;
    }

    public String getDesc() {
        return null;
    }

    @Override
    public View buildChartView(Context context) {

        String caption = "最近5天内注册率变化曲线";
        String xTitle = "日期";
        String yTitle = "百分比";
        int axesColor = Color.GRAY;
        int labelColor = Color.LTGRAY;
        String[] labels = new String[] { "2013/09/14", "2013/09/14", "2013/09/14", "2013/09/14", "2013/09/14" };// x轴的值
        Number[] values = new Number[] { 21, 42, 42, 98, 120 };// 相应的y轴的值
        String[] legend = new String[] { "注册率" };// 图例标题他的个数影响线条数
        int[] colors = new int[] { Color.CYAN };// 图例颜色决定线条颜色

        List<Number[]> valList = new ArrayList<Number[]>();
        valList.add(values);

        PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE };
        XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
        setChartSettings(renderer, caption, xTitle, yTitle, 0, 4, 0, 200, axesColor, labelColor);

        renderer.setXLabels(0);// [0表示不显示数字] 表示显示多少个坐标数量
        renderer.setYLabels(10);// 间隔
        renderer.setShowLabels(true);
        renderer.setXLabelsPadding(10);// 可以设置和title之间的间隔
        renderer.setApplyBackgroundColor(true);
        renderer.setBackgroundColor(Color.BLACK);
        renderer.setMargins(new int[] { 40, 40, 40, 40 });// 可以设置和legend之间的距离
        renderer.setXLabelsAngle(-20);// 设置角度你懂的
        for (int i = 0; i < legend.length; i++) {
            SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
            seriesRenderer.setDisplayChartValues(true);
        }
        for (int i = 0; i < labels.length; i++) {
            renderer.addXTextLabel(i + 1, labels[i]);
        }

        View view = ChartFactory.getLineChartView(context, buildBarDataset(legend, valList), renderer);

        return view;
    }

}